package com.hbnu.system.controller;


import com.hbnu.system.core.base.Rest;
import com.hbnu.system.model.entity.Opusauthor;
import com.hbnu.system.service.IOpusauthorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2023-05-16
 */
@RestController
@RequestMapping("/opusauthor")
@Api(tags = "作品的作者管理")
public class OpusauthorController {

    @Autowired
    IOpusauthorService iOpusauthorService;

    @ApiOperation("新增作品作者")
    @PostMapping("/addOpusAuthor")
    public Rest<String> addOpusAuthor(@RequestBody Opusauthor opusauthor){
        boolean ba = iOpusauthorService.addOpusauthor(opusauthor);
        return ba ? Rest.success() : Rest.failed();
    }

    @ApiOperation("删除作品作者信息")
    @GetMapping("/deleteOpusAuthor")
    public Rest<String> deleteOpusAuthor(String id){
        boolean ba1 = iOpusauthorService.deleteOpusauthor(id);
        return ba1 ? Rest.success():Rest.failed();
    }

    @ApiOperation("修改作品作者信息")
    @PostMapping("/updateOpusAuthor")
    public Rest<String> updateOpusAuthor(@RequestBody Opusauthor opusauthor){
        boolean ba2 = iOpusauthorService.updateOpusauthor(opusauthor);
        return ba2 ? Rest.success():Rest.failed();
    }

    @ApiOperation("根据作品编号搜索作者信息")
    @GetMapping("/selectAllAuthor")
    public Rest<List<Opusauthor>> selectAllAuthor(String id){
        List<Opusauthor> list = iOpusauthorService.listAuthor(id);
        return Rest.success(list,list.size());
    }

}

